import Vue from 'vue'
import Vuex from 'vuex'
// import todomain from '@/store/modules/todoheader'
// import todoheader from '@/store/modules/todoheader'
import createPresistedState from "vuex-persistedstate";
Vue.use(Vuex)
export default new Vuex.Store({
  plugins: [
    createPresistedState({
      key: 'TODO_LIST',
    })
  ],
  state: {
    taskName: '',
    isDone: false,
    type: 'all',
    todoList: []
  },
  mutations: {
    ADD_TASK(state, taskName) {
      state.todoList.push({
        taskName,
        isDone: false,
        id: Date.now(),
      })
      state.taskName = ''
    },
    DEL_TASK(state, id) {
      state.todoList = state.todoList.filter(item => item.id !== id)
    },
    CLEAR_DONE(state) {
      state.todoList = state.todoList.filter(item => !item.isDone)
    },
    CHANGE_TYPE(state, type) {
      state.type = type
    }
  },
  getters: {
    List: (state) => {
      if (state.type === 'yes') {
        return state.todoList.filter(item => item.isDone)
      } else if (state.type === 'no') {
        return state.todoList.filter(item => !item.isDone)
      }
      else {
        return state.todoList
      }
    }
  }
})